package com.tancire.web.controller.company;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.net.domain.CrmCompanyWithdraw;
import com.tancire.net.service.ICrmCompanyWithdrawService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * 客户提现记录Controller
 *
 * @author chencho
 * @date 2023-12-25
 */
@RestController
@RequestMapping("/net/crmCompanyWithdraw")
public class CrmCompanyWithdrawController extends BaseController {
    @Resource
    private ICrmCompanyWithdrawService crmCompanyWithdrawService;

    /**
     * 查询客户提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmCompanyWithdraw crmCompanyWithdraw) {
        startPage();
        List<CrmCompanyWithdraw> list = crmCompanyWithdrawService.selectCrmCompanyWithdrawList(crmCompanyWithdraw);
        return getDataTable(list);
    }

    /**
     * 导出客户提现记录列表
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:export')")
    @Log(title = "客户提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmCompanyWithdraw crmCompanyWithdraw) {
        List<CrmCompanyWithdraw> list = crmCompanyWithdrawService.selectCrmCompanyWithdrawList(crmCompanyWithdraw);
        ExcelUtil<CrmCompanyWithdraw> util = new ExcelUtil<CrmCompanyWithdraw>(CrmCompanyWithdraw.class);
        util.exportExcel(response, list, "客户提现记录数据");
    }

    /**
     * 获取客户提现记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crmCompanyWithdrawService.selectCrmCompanyWithdrawById(id));
    }

    /**
     * 审批通过
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:approve')")
    @Log(title = "审批通过", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/approve/pass/{id}")
    public AjaxResult approvePass(@PathVariable("id") Long id) {
        this.crmCompanyWithdrawService.approvePass(id);
        return AjaxResult.success();
    }

    /**
     * 审批拒绝
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:approve')")
    @Log(title = "审批拒绝", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/approve/refuse/{id}")
    public AjaxResult approveRefuse(@PathVariable("id") Long id) {
        this.crmCompanyWithdrawService.approveRefuse(id);
        return AjaxResult.success();
    }

    /**
     * 标记打款
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:payed')")
    @Log(title = "标记打款", businessType = BusinessType.UPDATE)
    @PostMapping("/approve/payed")
    public AjaxResult payed(@RequestBody CrmCompanyWithdraw crmCompanyWithdraw) {
        return toAjax(crmCompanyWithdrawService.payed(crmCompanyWithdraw));
    }

    /**
     * 新增客户提现记录
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:add')")
    @Log(title = "客户提现记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmCompanyWithdraw crmCompanyWithdraw) {
        return toAjax(crmCompanyWithdrawService.insertCrmCompanyWithdraw(crmCompanyWithdraw));
    }

    /**
     * 修改客户提现记录
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:edit')")
    @Log(title = "客户提现记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmCompanyWithdraw crmCompanyWithdraw) {
        return toAjax(crmCompanyWithdrawService.updateCrmCompanyWithdraw(crmCompanyWithdraw));
    }

    /**
     * 删除客户提现记录
     */
    @PreAuthorize("@ss.hasPermi('net:crmCompanyWithdraw:remove')")
    @Log(title = "客户提现记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crmCompanyWithdrawService.deleteCrmCompanyWithdrawByIds(ids));
    }
}
